<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>简介 | siphan</title>
    <meta name="description" content="一个简单易用的 JavaScript 前端加密库">
    <meta name="generator" content="VuePress 1.3.0">
    
    
    <link rel="preload" href="/siphan/assets/css/0.styles.bab5f12a.css" as="style"><link rel="preload" href="/siphan/assets/js/app.a096c374.js" as="script"><link rel="preload" href="/siphan/assets/js/2.b96ecc85.js" as="script"><link rel="preload" href="/siphan/assets/js/9.b0b386d5.js" as="script"><link rel="prefetch" href="/siphan/assets/js/10.e5803348.js"><link rel="prefetch" href="/siphan/assets/js/11.1506d706.js"><link rel="prefetch" href="/siphan/assets/js/12.9fea4da3.js"><link rel="prefetch" href="/siphan/assets/js/3.c42c2ebd.js"><link rel="prefetch" href="/siphan/assets/js/4.5f9aa696.js"><link rel="prefetch" href="/siphan/assets/js/5.537dfae2.js"><link rel="prefetch" href="/siphan/assets/js/6.c506cd42.js"><link rel="prefetch" href="/siphan/assets/js/7.0de11c07.js"><link rel="prefetch" href="/siphan/assets/js/8.83590e60.js">
    <link rel="stylesheet" href="/siphan/assets/css/0.styles.bab5f12a.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/siphan/" class="home-link router-link-active"><img src="https://s2.ax1x.com/2020/02/26/3aERFe.png" alt="siphan" class="logo"> <span class="site-name can-hide">siphan</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/siphan/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/siphan/guide/" class="nav-link router-link-exact-active router-link-active">
  入门
</a></div><div class="nav-item"><a href="/siphan/API/" class="nav-link">
  API
</a></div><div class="nav-item"><a href="http://service.shawroger.com/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  示例
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><a href="https://gitee.com/shawroger/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  仓库
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/siphan/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/siphan/guide/" class="nav-link router-link-exact-active router-link-active">
  入门
</a></div><div class="nav-item"><a href="/siphan/API/" class="nav-link">
  API
</a></div><div class="nav-item"><a href="http://service.shawroger.com/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  示例
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><a href="https://gitee.com/shawroger/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  仓库
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>入门</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/siphan/guide/" class="active sidebar-link">简介</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/siphan/guide/#工具定位" class="sidebar-link">工具定位</a></li><li class="sidebar-sub-header"><a href="/siphan/guide/#特性" class="sidebar-link">特性</a></li></ul></li><li><a href="/siphan/guide/start.html" class="sidebar-link">快速开始</a></li><li><a href="/siphan/guide/principle.html" class="sidebar-link">原理</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="简介"><a href="#简介" class="header-anchor">#</a> 简介</h1> <h2 id="工具定位"><a href="#工具定位" class="header-anchor">#</a> 工具定位</h2> <p><strong>Siphan</strong> 是一个采用 <strong>TypeScript</strong> 编写的 <strong>JavaScript</strong> 前端加密库，与一般的加密库不同，<strong>Siphan</strong> 既可以在服务端使用，还可以在前端使用，并且可以保证其安全性。</p> <h2 id="特性"><a href="#特性" class="header-anchor">#</a> 特性</h2> <ul><li>直接加密 <strong>ASCII</strong> 字符</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> encrypt <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;siphan&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> <span class="token punctuation">{</span> cipher<span class="token punctuation">,</span> solution <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">encrypt</span><span class="token punctuation">(</span><span class="token string">&quot;hello, world&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><ul><li>支持加密所有 <strong>UTF8</strong> 字符</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> encryptUTF8 <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;siphan&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> <span class="token punctuation">{</span> cipher<span class="token punctuation">,</span> solution <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">encryptUTF8</span><span class="token punctuation">(</span><span class="token string">&quot;你好，世界&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><ul><li>实现以上加密过程的密钥解码</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> encrypt<span class="token punctuation">,</span> decrypt <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;siphan&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> <span class="token punctuation">{</span> cipher<span class="token punctuation">,</span> solution <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">encrypt</span><span class="token punctuation">(</span><span class="token string">&quot;hello, world&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> result  <span class="token operator">=</span> <span class="token function">decrypt</span><span class="token punctuation">(</span>cipher<span class="token punctuation">,</span> solution<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> encryptUTF8<span class="token punctuation">,</span> decryptUTF8 <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;siphan&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> <span class="token punctuation">{</span> cipher<span class="token punctuation">,</span> solution <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">encryptUTF8</span><span class="token punctuation">(</span><span class="token string">&quot;你好，世界&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> result  <span class="token operator">=</span> <span class="token function">decrypt</span><span class="token punctuation">(</span>cipher<span class="token punctuation">,</span> solution<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><ul><li>允许使用已知密钥来进行加密</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createKey<span class="token punctuation">,</span> encryptAs <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;siphan&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> key <span class="token operator">=</span> <span class="token function">createKey</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> <span class="token punctuation">{</span> cipher<span class="token punctuation">,</span> solution <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">encryptAs</span><span class="token punctuation">(</span><span class="token string">&quot;hello, world&quot;</span><span class="token punctuation">,</span> key<span class="token punctuation">)</span><span class="token punctuation">;</span>
solution <span class="token operator">===</span> key <span class="token comment">// true</span>

</code></pre></div><ul><li>允许使用自定义字典来进行加密</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> configKey<span class="token punctuation">,</span> encrypt <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;siphan&quot;</span><span class="token punctuation">;</span>

<span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    configKey<span class="token punctuation">.</span><span class="token function">setKey</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
        <span class="token string">&quot;a&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;b&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;c&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;d&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;e&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;f&quot;</span><span class="token punctuation">,</span> 
        <span class="token string">&quot;g&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;h&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;i&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;j&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;k&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;l&quot;</span>
    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">const</span> <span class="token punctuation">{</span> cipher <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">encrypt</span><span class="token punctuation">(</span><span class="token string">&quot;custom dictionary&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    configKey<span class="token punctuation">.</span><span class="token function">resetKey</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// reset</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><!----> <span class="next"><a href="/siphan/guide/start.html">
        快速开始
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/siphan/assets/js/app.a096c374.js" defer></script><script src="/siphan/assets/js/2.b96ecc85.js" defer></script><script src="/siphan/assets/js/9.b0b386d5.js" defer></script>
  </body>
</html>
